<template>
  <div>
    <el-table
      :data="banners"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children' }"
    >
      <el-table-column prop="id" label="编号" sortable width="180">
      </el-table-column>
      <el-table-column prop="title" label="轮播图标题" sortable width="180">
      </el-table-column>
      <el-table-column label="图片">
        <template v-slot="scope">
          <img v-if="scope.row.img!==''"
            style="width: 100px; height: 100px"
            :src="$pregImg + scope.row.img"
            :alt="scope.row.catename"
          />
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template v-slot="scope">
          <el-button v-if="scope.row.status === 1" type="success"
            >启用</el-button
          >
          <el-button v-else type="danger"> 禁用 </el-button>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="edit(scope.row.id)">编辑</el-button>
          <el-button type="danger" @click="del(scope.row.id)"> 删除 </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { successAlert } from '../../../utils/alert';
import {bannersDel} from "../../../request/api"
export default {
  computed: {
    ...mapGetters({
      banners: "banners/banners",
    }),
  },
  methods: {
    ...mapActions({
      bannersActions: "banners/bannersActions",
    }),
    del(id) {
      // this.cateDelActions({ id });
      // this.bannersActions();
      bannersDel({id});
      successAlert("删除成功")
       this.bannersActions();
    },
    edit(id) {
      this.$emit("edit", id);
    },
  },
  mounted() {
    this.bannersActions();
  },
};
</script>

<style>
</style>